package com.atguigu.gmall.product.controller;

import com.atguigu.gmall.common.result.Result;

import com.atguigu.gmall.model.product.BaseCategory1;
import com.atguigu.gmall.model.product.BaseCategory2;

import com.atguigu.gmall.model.product.BaseCategory3;
import com.atguigu.gmall.product.service.BaseCategoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/admin/product")
public class GetCategoryController {

    @Autowired
    BaseCategoryService baseCategoryService;


    /**
     * 获取一级分类
     * @return
     */
    @GetMapping("/getCategory1")
    public Result getCategoryController1(){

        List<BaseCategory1> category1List =baseCategoryService.findbaseCategory1();
        return Result.ok(category1List);
    }

    /**
     * 获取二级分类
     * @return
     */
    @GetMapping("/getCategory2/{id}")
    public Result getCategoryController2(@PathVariable("id") Long id){
        List<BaseCategory2> category2List=baseCategoryService.findbaseCategory2ByC1id(id);
        return Result.ok(category2List);
    }

    /**
     * 获取三级列表
     * @param category2Id
     * @return
     */
    @GetMapping("/getCategory3/{category2Id}")
    public Result getCategoryController3(@PathVariable("category2Id") Long category2Id){
        List<BaseCategory3> category3List=baseCategoryService.findbaseCategory3ByC2id(category2Id);
        return Result.ok(category3List);
    }


}
